//
// Created by 123 on 2025/1/10.
//
#include "vector"
#include "algorithm"
#include "iostream"

//一元谓词
struct GreaterFive{
    bool operator()(int val){
        return val > 5;
    }
};

void test(){
    std::vector<int> v;
    for (int i = 0; i < 10; ++i) {
        v.push_back(i);
    }

    std::vector<int>::iterator it = std::find_if(v.begin(),v.end(),GreaterFive());
    if(it == v.end()){
        std::cout << "can not find " << std::endl;
    }else{
        std::cout << "got it" << std::endl;
    }
    std::cout << *it << std::endl;
    it++;
    std::cout << *it << std::endl;

}

//二元谓词
class MyCompare{
public:
    bool operator()(int num1,int num2){
        return num1 > num2;
    }
};

void test2(){
    std::vector<int> v;
    v.push_back(10);
    v.push_back(40);
    v.push_back(20);
    v.push_back(30);

    std::sort(v.begin(),v.end());
    for(std::vector<int>::iterator it=v.begin();it!=v.end();it++){
        std::cout << *it << " ";
    }
    std::cout << std::endl;
    std::cout << "-----------------------------" << std::endl;
    //使用函数对象，改变算法规则
    std::sort(v.begin(),v.end(),MyCompare());
    for(std::vector<int>::iterator it=v.begin();it!=v.end();it++){
        std::cout << *it << " ";
    }
    std::cout << std::endl;

}

int main146(){
//    test();
    test2();
    return 0;
}